﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace CodeCounsel.SharePoint.RibbonDesigner.Model
{
    [XName("CustomAction", Namespaces.CommandUIText)]
    public class CustomAction
        : DomainElement
    {
        public bool IsCommandUIAction
        {
            get { return Location == "CommandUI.Ribbon"; }
        }

        public string Id
        {
            get { return DataModel.GetAttributeValue(Schema.Id); }
            set { DataModel.SetAttributeValue(Schema.Id, value); }
        }

        public string Location
        {
            get { return DataModel.GetAttributeValue(Schema.Location); }
            set { DataModel.SetAttributeValue(Schema.Location, value); }
        }

        public CommandUIExtension CommandUIExtension
        {
            get { return Children.OfType<CommandUIExtension>().FirstOrDefault(); }
        }

        public CustomAction(XElement dataModel, DomainModelSource source)
            : base(dataModel, source)
        {
        }

        public CustomAction()
        {
        }
    }
}
